<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Mind=Boggled - ScrambleWithFriends Solver</title>
</head>
<body style="background-color:#963;text-align:center;color:#def;text-shadow:-3px 0 #630,0 3px #630,1px 0 black,0 -3px #630" onload="f(4,4)">
<div style="margin-bottom:26px;font-size:42px;font-weight:bold;font-family:comic sans ms">Mind=Boggled</div>
<form onsubmit="try{o()}catch(e){};return false">
<div id="i"></div>
<input id="s" style="margin:16px" type="submit" value="SOLVE"/>&nbsp;<span id="c" style="text-shadow:none"></span>
</form>
<div id="o" style="font-size:36px;font-weight:bold;font-family:arial;position:relative;float:left;left:50%"></div>
<div style="position:absolute;bottom:0;text-shadow:none;color:#fff">&copy; C-Walt Solutions | <a style="color:#eef" href="http://whatarethesescribbles.appspot.com">DrawSomething Solver</a> | <a style="color:#eef" href="http://whatarethesescrambles.appspot.com">ScrambleWithFriends Solver</a></div>
</body>
</html>
<script>(function(){
var z = function(x, y){return x > y ? 1 : x < y ? -1 : 0}
var g = function(v){return document.getElementById(v)}

var w=0, h=0, m=15, d=[], l={}

var p=[], pt=[]
var s = function(r, c){
	var i = r*w + c
	if(p[i])return
	p[i] = true

	pt.push(d[i])
	if(pt[1] && wl[pt[0].charCodeAt(0) + pt[1].charCodeAt(0) - 130][pt.join('')])
		l[pt.join('').replace(/Q/g, 'QU')] = p.slice(0)

	if(pt.length < m){
		if(r > 0){
			if(c > 0)s(r-1, c-1)
			s(r-1, c)
			if(c < w-1)s(r-1, c+1)
		}
		if(c > 0)s(r, c-1)
		if(c < w-1)s(r, c+1)
		if(r < h-1){
			if(c > 0)s(r+1, c-1)
			s(r+1, c)
			if(c < w-1)s(r+1, c+1)
		}
	}

	p[i] = false
	pt.pop()
}

window.o = function(){
	var div = '<div style="float:left;position:relative;right:50%;margin-right:18px">'
	g('s').disabled = true
	g('o').innerHTML = div + 'Computing...<span id="p"></span></div>'

	var r=0, t0=new Date().getTime()
	l = {}
	var f1 = function(){
	setTimeout(function(){
		for(var c=0; c<w; c++)s(r, c)
		g('p').innerHTML = (100*(r+1)/h).toFixed(0) + '%'
		if(++r < h)f1()
		else f2()
	}, 22)
	}
	var f2 = function(){
	var x = []
	for(k in l)x.push(k)
	x = x.sort(function(a, b){return z(b.length, a.length) || z(a, b)})

	var t = []
	for(var i=0,il=x.length; i<il; i++){
		if(!(i % 15))t.push(div)
		t.push('<div style="padding:2px 4px" onmouseover="h(this, \'' + x[i] + '\')" onmouseout="h2(this)">' + x[i] + '</div>')
		if((i % 15) === 14)t.push('</div>')
	}

	g('s').disabled = false
	g('o').innerHTML = t.join('')
	g('c').innerHTML = x.length + ' word' + (x.length === 1 ? '' : 's') + ' found in ' + ((new Date().getTime() - t0) / 1000).toFixed(2) + 's'
	}
	f1()
}

window.h = function(n, s){
	n.style.backgroundColor = '#fdb'
	for(var r=0; r<h; r++)
		for(var c=0; c<w; c++)
			if(!l[s][r*w + c])
				g('i' + r + '-' + c).style.backgroundColor = '#c96'
}
window.h2 = function(n){
	n.style.backgroundColor = '#963'
	for(var r=0; r<h; r++)
		for(var c=0; c<w; c++)
			g('i' + r + '-' + c).style.backgroundColor = '#fdb'
}

window.n = function(r, c){
	var x = g('i' + r + '-' + c).value
	var i = r*w + c
	if(e.keyCode === 8 && (x || !d[i]) && r + c > 0)
			g(c > 0 ? 'i' + r + '-' + (c-1) : 'i' + (r-1) + '-' + (w-1)).select()
	d[i] = x.toUpperCase()
	if(!d[i] || e.keyCode === 8)return
	if(r < h - 1 || c < w - 1)
		g(c < w - 1 ? 'i' + r + '-' + (c+1) : 'i' + (r+1) + '-0').select()
}

window.f = function(tw, th){
	w = tw; h = th
	var s = []
	for(var r=0; r<h; r++){
		for(var c=0; c<w; c++)
			s.push('<input id="i' + r + '-' + c + '" maxlength="1" style="border:3px solid #963;background-color:#fdb;color:#630;width:42px;font-size:38px;font-weight:bold;text-align:center;text-transform:uppercase" onclick="this.select()" onkeypress="e=event;setTimeout(function(){n(' + r + ',' + c + ')},9)"/>')
		s.push('<br/>')
	}
	g('i').innerHTML = s.join('')
	g('i0-0').select()
}

var t = document.createElement('script')
t.src = 'zynga.js'
document.head.appendChild(t)
})()</script>
